#include "DaterIcon.h"
#include "AnimationWindowTrans.h"
#include "DaterDaterWindow.h"
#include "DaterBaseWindowManager.h"

Icon::Icon(MainWindow* linkedWindow, CEGUI::Window* rootWindow) : _linkedWindow(linkedWindow) , _root(rootWindow)
{
	using namespace CEGUI;

	_root->subscribeEvent(
		Window::EventMouseDoubleClick,
		Event::Subscriber(&Icon::handle_DoubleClicked, this));
	//_linkedWindow->getRoot()->subscribeEvent(AnimationInstance::EventAnimationEnded, Event::Subscriber(&Icon::handle_releaseAnimationInstance, this));
}

bool Icon::handle_DoubleClicked(const CEGUI::EventArgs& args)
{
	static_cast<DaterWindow*>(BaseWindowManager::getSingleton().getWindow("Root"))->gotoMainWindow(_linkedWindow);

	return true;
}

bool Icon::handle_releaseAnimationInstance(const CEGUI::EventArgs& args)
{
	const CEGUI::AnimationEventArgs& animationArgs = static_cast<const CEGUI::AnimationEventArgs&>(args);

	CEGUI::AnimationManager::getSingleton().destroyAnimationInstance(animationArgs.instance);

	return true;
}